import { Frame } from "./Frame";
import { FrameUtil } from "../FrameUtil";
type int = number;
//class FlashFrame
    
    export  class FlashFrame extends Frame
    {
        constructor(arg1: number=24)
        {
            super(arg1);
            this._sprite = new Object /* flash.display.Sprite */();
            return;
        }

        public /* override */ play(): void
        {
            super.play();
            this._sprite.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrameHandler);
            this._count = 0;
            this._startTime = flash.utils.getTimer();
            return;
        }

        public /* override */ stop(): void
        {
            super.stop();
            this._sprite.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrameHandler);
            return;
        }

        /* internal  */recoupFrames(arg1: uint=1, arg2: number=33): void
        {
            var loc1=0;
            while (loc1 < arg1) 
            {
                renderer(arg2);
                ++loc1;
            }
            return;
        }

        protected /* override */ onEnterFrameHandler(arg1: Object /* flash.events.Event */=null): void
        {
            var loc2=0;
            var loc3=0;
            var loc1=flash.utils.getTimer();
            FrameUtil.frameStartTime = loc1;
            if (this._prevTime != 0) 
            {
                loc2 = loc1 - this._prevTime;
                if ((loc3 = uint(1000 / loc2)) >= FlashFrame.RealFrameRate) 
                {
                    renderer(loc2);
                }
                else 
                {
                    this.recoupFrames(int(FlashFrame.RealFrameRate / loc3));
                }
            }
            else 
            {
                loc2 = 0;
            }
            this._prevTime = loc1;
            FrameUtil.frameProTimer = FrameUtil.frameProTimer + (flash.utils.getTimer() - loc1);
            FlashFrame.FramesCount = 0;
            var loc4;
            var loc5=((loc4 = this)._count + 1);
            loc4._count = loc5;
            if (this._count == 50) 
            {
                FlashFrame.AverageTime = (flash.utils.getTimer() - this._startTime) / this._count;
                this._count = 0;
                this._startTime = flash.utils.getTimer();
            }
            return;
        }

        private static /* const */RealFrameRate: int=30;

        private /* var */_sprite: Object /* flash.display.Sprite */;

        private /* var */_isBrowserAvailable: Boolean=false;

        private /* var */_count: int=0;

        private /* var */_accruedTime: number;

        private /* var */_startTime: number;

        private /* var */_prevTime: int=0;

        public static /* var */AverageTime: int=33;

        public static /* var */FramesCount: int=0;
    }

            FlashFrame.AverageTime = 33;
            FlashFrame.FramesCount = 0;
        